import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import axios from 'axios'

//导入pinia中的定义 全局数据的一个函数 defineStore
export const useJokerStore = defineStore('joker', () => {
  //状态变量
  const joker = ref('狐狸很容易摔跤，因为狡猾')

  const refreshJoke = async () => {
    // setTimeout(() => {
    //   joker.value = 'xxxxxxxxx'
    // }, 1000)
    //调用接口获取笑话
    //axios 调用笑话接口，获取到笑话之后，更改joke.value
    const res = await axios.get('https://api-vue-base.itheima.net/api/joke')
    joker.value = res.data
  }
  return { joker, refreshJoke }
})
